package com.dgut.cbd.finalexp.myController;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.core.annotation.CurrentSecurityContext;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class TestController {

    @GetMapping(value  = {"/test","/user/test","/admin/test"})
    @ResponseBody
    String test(Authentication auth1,
                @AuthenticationPrincipal UserDetails userDetails,
                @CurrentSecurityContext SecurityContext securityContext,
                @CurrentSecurityContext(expression = "authentication") Authentication auth2) {
        System.out.println("auth1 = " + auth1);
        System.out.println("userDetails = " + userDetails);
        System.out.println("securityContext = " + securityContext);
        System.out.println("auth2 = " + auth2);

        return SecurityContextHolder.getContext().getAuthentication().getPrincipal().toString();
    }

}
